package cn.chenfyuan.demoapplication.service.impl;

import java.io.Serializable;
import java.util.List;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.data.redis.core.ReactiveRedisTemplate;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.data.redis.core.ValueOperations;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import com.baomidou.mybatisplus.plugins.Page;
import cn.chenfyuan.demoapplication.entity.SysUser;
import cn.chenfyuan.demoapplication.mapper.SysUserMapper;
import cn.chenfyuan.demoapplication.service.SysUserService;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;

/**
 * <p>
 *  用户服务实现类
 * </p>
 *
 * @author linweijian
 * @since 2018-05-02
 */
@Slf4j
@Service
public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> implements SysUserService {
	private final SysUserMapper sysUserMapper;
	public SysUserServiceImpl(SysUserMapper sysUserMapper) {
		this.sysUserMapper = sysUserMapper;
	}

    @Autowired
    private RedisTemplate redisTemplate;

    @Cacheable(value = "selectPage",key = "#page.getCurrent()")
    @Override
    public Page<SysUser> selectPage(Page<SysUser> page, SysUser vo) {
        log.debug("####################缓存成功############################");
        redisTemplate.opsForValue().set("name1","林卫键");
        page.setRecords(sysUserMapper.selectPage(page, vo));
        return page;
    }

	@Override
	public SysUser findByName(String userName) {
		return sysUserMapper.findByName(userName);
	}



    @Cacheable(value = "user", key = "#userId")
    @Override
    public SysUser get(String userId) {
        SysUser u = this.sysUserMapper.selectById(userId);
        return u;
    }

}
